﻿<%@ Page Language="C#" AutoEventWireup="true" CodeFile="card_manage.aspx.cs" Inherits="Default3" MaintainScrollPositionOnPostback="true" Title="油卡管理 - 基础数据" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <style type="text/css">
        .style7 {
            font-size: small;
            text-align: left;
            width: 80%;
            float: left;
            display: inline;
        }

        .style21 {
            font-size: small;
        }

        .right {
            width: 18%;
            float: right;
        }

        #newdata {
            color: rgb(51, 51, 51);
            font-size: small;
            border-collapse: collapse;
        }
        .auto-style1 {
            height: 57px;
        }
    </style>
</head>
<body background="images/login-bg.jpg">
    <form id="form1" runat="server">
        <div style="text-align: center">
            <div class="style7">
                <span>当前位置：</span><asp:HyperLink ID="HyperLink1" runat="server"
                    NavigateUrl="~/index.aspx" Style="color: #000000"
                    ToolTip="点击返回主页面">主页面</asp:HyperLink>
                <span>→ 编辑</span>油卡基础库<br class="style7" />
                <br />
            </div>
            <div class="right">
                <br />
            </div>
            <br />
            <div>
                <table id="table7" align="center" border="0" cellpadding="0" cellspacing="0"
                        width="95%">
                        <tr>
                            <td height="10" width="9">
                                <img align="absMiddle" border="0" height="10" src="images/l_1_1.jpg"
                                    width="9" /></td>
                            <td background="images/l_1_8.jpg" width="100%"></td>
                            <td height="10" width="9">
                                <img align="absMiddle" border="0" height="10" src="images/l_1_7.jpg"
                                    width="9" /></td>
                        </tr>
                        <tr>
                            <td background="images/l_1_2.jpg" class="style22"></td>
                            <td align="left" bgcolor="#ffffff" valign="top" width="100%" class="style22">
                                <table id="table8" align="center" border="0" cellpadding="0" cellspacing="0"
                                    width="100%">
                                    <tr>
                                        <td class="auto-style1"><b>&nbsp; 单位:<asp:DropDownList ID="ddlDW0" runat="server" DataSourceID="dsDW" DataTextField="ch_pwname" DataValueField="chejian" AppendDataBoundItems="True">
                                    <asp:ListItem Selected="True" Value="">==请选择==</asp:ListItem>
                                </asp:DropDownList>
            &nbsp;卡号:<asp:TextBox ID="txtCardNum0" runat="server" Width="120px" />
            &nbsp; 车号:<asp:TextBox ID="txtCarNum0" runat="server" Width="94px" />
            &nbsp; 持卡人:<asp:TextBox ID="txtOwner0" runat="server" Width="73px" />
            &nbsp;主页面
            <asp:CheckBox ID="cbShow0" runat="server" Text="显示" />
            <asp:CheckBox ID="cbShow1" runat="server"  Text="隐藏" />
            &nbsp;
            <asp:CheckBox ID="cbEnabled0" runat="server" Text="启用" />
            <asp:CheckBox ID="cbEnabled1" runat="server"  Text="禁用" /></b>
                                            <br />
                                            <br />
                                        </td>
                                    </tr>
                                    <tr>
                                        <td>&nbsp;
                                <asp:Label ID="Label_tiaojian" runat="server" Style="color: #FF3300"
                                    Text="Label"></asp:Label>
                                        </td>
                                    </tr>
                                    <tr>
                                        <td>&nbsp;</td>
                                    </tr>
                                    <tr>
                                        <td>
                                            <table id="table9" border="0" cellpadding="0" cellspacing="0" width="100%">
                                                <tr>
                                                    <td background="images/line.jpg" height="1"></td>
                                                </tr>
                                                <tr>
                                                    <td>
                                                        <table id="table10" border="0" cellpadding="0" cellspacing="0" width="100%">
                                                            <tr>
                                                                <td align="middle" height="35" width="24%">
                                                                    <img align="absMiddle" border="0" height="25" src="images/l_1_10.jpg"
                                                                        width="19" /></td>
                                                                <td align="left" style="text-align: center" width="54%">
                                                                    <asp:ImageButton ID="ImageButton1" runat="server" ImageUrl="~/images/sub_1.jpg"
                                                                        OnClick="ImageButton1_Click" />
                                                                    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                                                        <asp:ImageButton ID="ImageButton2" runat="server"
                                                            ImageUrl="~/images/sub_2.jpg" OnClick="ImageButton2_Click" />
                                                                </td>
                                                                <td align="middle" valign="center" width="22%">
                                                                    <img align="absMiddle" border="0" height="15" src="images/l_1_12.jpg"
                                                                        width="49" /></td>
                                                            </tr>
                                                        </table>
                                                    </td>
                                                </tr>
                                            </table>
                                        </td>
                                    </tr>
                                </table>
                            </td>
                            <td background="images/l_1_6.jpg" class="style22"></td>
                        </tr>
                        <tr>
                            <td height="10" width="9">
                                <img align="absMiddle" border="0" height="10" src="images/l_1_3.jpg"
                                    width="9" /></td>
                            <td background="images/l_1_4.jpg"></td>
                            <td height="10" width="9">
                                <img align="absMiddle" border="0" height="10" src="images/l_1_5.jpg"
                                    width="9" /></td>
                        </tr>
                    </table>
            </div>
            <br />
            <b>
                <br />
                油卡基础数据列表
                <asp:LinkButton ID="UpdateAll" runat="server" style="float:right;font-size:small;font-weight:normal;" NavigateUrl="#" OnClick="UpdateAll_Click">更新车间班组</asp:LinkButton><br />
                <br />
                <asp:GridView ID="GridView1" runat="server" AllowPaging="True"
                    AutoGenerateColumns="False" CellPadding="4" DataKeyNames="id,cardnum,carnum"
                    DataSourceID="SqlDataSource1" EmptyDataText="没有油卡数据"
                    EnableModelValidation="True" ForeColor="#333333" GridLines="None"
                    Style="text-align: center; font-size: small"
                    OnRowDataBound="GridView1_RowDataBound" OnRowDeleted="GridView1_RowDeleted" PageSize="30" OnPageIndexChanging="GridView1_PageIndexChanging" OnRowCommand="GridView1_RowCommand">
                    <AlternatingRowStyle BackColor="White" />
                    <Columns>
                        <asp:CommandField ShowDeleteButton="True" />
                        <asp:TemplateField HeaderText="序号" ItemStyle-ForeColor="Gray"></asp:TemplateField>
                        <asp:BoundField DataField="id" HeaderText="id" InsertVisible="False" ReadOnly="True" SortExpression="id" Visible="False" />
                        <asp:TemplateField HeaderText="车间" SortExpression="jgname">
                            <ItemTemplate>
                                <asp:Label ID="Label1" runat="server" Text='<%# Bind("jgname") %>'></asp:Label>
                            </ItemTemplate>
                        </asp:TemplateField>
                        <asp:TemplateField HeaderText="班组" SortExpression="bzname">
                            <ItemTemplate>
                                <asp:Label ID="Label2" runat="server" Text='<%# Bind("bzname") %>'></asp:Label>
                            </ItemTemplate>
                        </asp:TemplateField>
                        <asp:BoundField DataField="cardnum" HeaderText="卡号" ReadOnly="true" SortExpression="cardnum" ControlStyle-Width="80" ItemStyle-Width="80" />
                        <asp:BoundField DataField="carnum" HeaderText="车号" ReadOnly="true" SortExpression="carnum" ControlStyle-Width="80" ItemStyle-Width="80"/>
                        <asp:BoundField DataField="balance" HeaderText="余额（元）" ItemStyle-HorizontalAlign="Right" HeaderStyle-HorizontalAlign="Right" ControlStyle-Width="80" ItemStyle-Width="80" SortExpression="balance" DataFormatString="{0:C}" />
                        <asp:BoundField DataField="owner" HeaderText="持卡人" SortExpression="owner" ControlStyle-Width="70" ItemStyle-Width="70" />
                        <asp:TemplateField HeaderText="持卡人变动情况" SortExpression="ownerdetail" ControlStyle-Width="300" ItemStyle-Width="300">
                            <EditItemTemplate>
                                <asp:TextBox ID="TextBox4" runat="server" Text='<%# Bind("ownerdetail") %>' TextMode="MultiLine" Rows="4"></asp:TextBox>
                            </EditItemTemplate>
                            <ItemTemplate>
                                <asp:Label ID="Label4" runat="server" Text='<%# Bind("ownerdetail") %>'></asp:Label>
                            </ItemTemplate>
                        </asp:TemplateField>
                        <asp:CheckBoxField DataField="isshowinmain" HeaderText="主页面<br/>显示" SortExpression="isshowinmain" />
                        <asp:CheckBoxField DataField="enabled" HeaderText="启用" SortExpression="enabled" />
                        <asp:BoundField DataField="ordernum" HeaderText="排序" SortExpression="ordernum" ControlStyle-Width="30" ItemStyle-Width="30" />
                        <asp:CommandField ShowEditButton="True" ItemStyle-Width="70" />
                        <asp:TemplateField ShowHeader="False" ItemStyle-Width="50">
                            <ItemTemplate>
                                <asp:LinkButton ID="lbtnUpdateCJBZ" runat="server" CausesValidation="False" CommandName="UpdateCJBZ" CommandArgument='<%# Eval("cardnum")%>' Text="更新"></asp:LinkButton>
                            </ItemTemplate>
                        </asp:TemplateField>
                    </Columns>
                    <EditRowStyle BackColor="#2461BF" />
                    <FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
                    <HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
                    <PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" />
                    <RowStyle BackColor="#EFF3FB" />
                    <SelectedRowStyle BackColor="#336699" Font-Bold="True" ForeColor="#333333" />
                </asp:GridView>
                <asp:SqlDataSource ID="SqlDataSource1" runat="server"
                    ConnectionString="<%$ ConnectionStrings:xxnewsConnectionString %>"
                    DeleteCommand="DELETE FROM youkaguanli_card WHERE (id = @id);DELETE FROM youkaguanli_card_detail WHERE (cardid=@cardnum) and changetime is null;"
                    InsertCommand="INSERT INTO youkaguanli_card(jgname, bzname, cardnum, carnum, owner, ownerdetail, balance, isshowinmain, enabled, ordernum, addname, addtime, addip) VALUES (@jgname, @bzname, @cardnum, @carnum, @owner, @ownerdetail, @balance, @isshowinmain, @enabled, @ordernum, @addname, GETDATE(), @addip);
                                    INSERT INTO youkaguanli_card_detail ([cardid],[inout],[amount], [balance],[currentowner]) VALUES (@cardnum,1,@balance,@balance,@owner);"
                    SelectCommand="SELECT * FROM [youkaguanli_card] ORDER BY [enabled] DESC,[ordernum], [jgname], [bzname]"
                    UpdateCommand="UPDATE youkaguanli_card SET owner = @owner, ownerdetail = @ownerdetail, balance = @balance, isshowinmain = @isshowinmain, enabled = @enabled, ordernum = @ordernum where id=@id;
                                   UPDATE t SET balance = @balance,memo=ISNULL(memo,'')+'&lt;br/&gt;'+CONVERT(varchar(20), GETDATE(), 23)+'修改前余额：'+cast(balance as varchar(100))+',持有人：'+currentowner--,currentowner=@owner
FROM (select ROW_NUMBER() over (order by changetime desc,addtime desc,id desc) as i,ka.*
from youkaguanli_card_detail as ka where cardid=@cardnum) t where i=1">
                    <DeleteParameters>
                        <asp:Parameter Name="id" />
                        <asp:Parameter Name="cardnum" />
                    </DeleteParameters>
                    <InsertParameters>
                        <asp:Parameter Name="jgname" />
                        <asp:Parameter Name="bzname" />
                        <asp:Parameter Name="cardnum" />
                        <asp:Parameter Name="carnum" />
                        <asp:Parameter Name="owner" />
                        <asp:Parameter Name="ownerdetail" />
                        <asp:Parameter Name="balance" Type="Decimal" />
                        <asp:Parameter Name="isshowinmain" Type="Boolean" />
                        <asp:Parameter Name="enabled" Type="Boolean" />
                        <asp:Parameter Name="ordernum" Type="Decimal" />
                        <asp:Parameter Name="addname" />
                        <asp:Parameter Name="addip" />
                    </InsertParameters>
                    <UpdateParameters>
                        <asp:Parameter Name="owner" />
                        <asp:Parameter Name="ownerdetail" />
                        <asp:Parameter Name="balance"  Type="Decimal"/>
                        <asp:Parameter Name="isshowinmain" Type="Boolean"/>
                        <asp:Parameter Name="enabled" Type="Boolean"/>
                        <asp:Parameter Name="ordernum" Type="Decimal"/>
                        <asp:Parameter Name="id" />
<asp:Parameter Name="cardnum"></asp:Parameter>
                    </UpdateParameters>
                </asp:SqlDataSource>
                <asp:SqlDataSource ID="dsDW" runat="server"
                    ConnectionString="<%$ ConnectionStrings:xxnewsConnectionString %>"
                    SelectCommand="select ch_pwname,ch_pwname+'|'+bm_leibie as chejian FROM siteman WHERE (ch_pwname = '设备科') or (ch_pwname = '材料科') or ch_pwname in(SELECT DISTINCT banzu1 FROM tcjcb) or ch_pwname in(SELECT DISTINCT banzu1 FROM tcjcb_qiche)  or ch_pwname in(SELECT DISTINCT banzu1 FROM tcjcb_fadianji) group by ch_pwname,in_id,ch_px,bm_leibie ORDER BY ch_px"></asp:SqlDataSource>
                <asp:SqlDataSource ID="dsCarNum" runat="server"
                    ConnectionString="<%$ ConnectionStrings:xxnewsConnectionString %>"
                    SelectCommand="SELECT chehao, xuhao, 1 AS type, banzu1 FROM tcjcb_qiche WHERE (banzu1 =@banzu1) UNION SELECT chehao, xuhao, 2 AS type, banzu1 FROM tcjcb WHERE (banzu1 =@banzu1) ORDER BY type, xuhao">
                    <SelectParameters>
                        <asp:ControlParameter ControlID="ddlDW" Name="banzu1" PropertyName="SelectedItem.Text" Type="String" />
                    </SelectParameters>
                </asp:SqlDataSource>
                <br />
                <table id="newdata" border="0" cellspacing="0" cellpadding="4">
                    <tbody>
                        <tr align="left">
                            <td align="right">单位<font color="red">*</font></td>
                            <td>
                                <asp:DropDownList ID="ddlDW" runat="server" AutoPostBack="true" DataSourceID="dsDW" DataTextField="ch_pwname" DataValueField="chejian" AppendDataBoundItems="True" OnSelectedIndexChanged="ddlDW_SelectedIndexChanged">
                                    <asp:ListItem Selected="True" Value="">==请选择==</asp:ListItem>
                                </asp:DropDownList>
                                <asp:RequiredFieldValidator ID="vDW" runat="server" ControlToValidate="ddlDW" ErrorMessage="请选择单位" SetFocusOnError="True" ValidationGroup="Insert"></asp:RequiredFieldValidator>
                            </td>
                        </tr>
                        <tr align="left">
                            <td align="right">卡号<font color="red">*</font></td>
                            <td>
                                <asp:TextBox ID="txtCardNum" runat="server" />
                                <asp:RequiredFieldValidator ID="vCardNum" runat="server" ControlToValidate="txtCardNum" ErrorMessage="请输入卡号" SetFocusOnError="True" ValidationGroup="Insert"></asp:RequiredFieldValidator>
                            </td>
                        </tr>
                        <tr align="left">
                            <td align="right">车号</td>
                            <td>
                                <asp:DropDownList ID="ddlCarNum" runat="server" DataSourceID="dsCarNum" DataTextField="chehao" DataValueField="chehao" AppendDataBoundItems="True">
                                    <asp:ListItem Selected="True" Value="">==请选择==</asp:ListItem>
                                </asp:DropDownList>
                            </td>
                        </tr>
                        <tr align="left">
                            <td align="right">持卡人<font color="red">*</font></td>
                            <td>
                                <asp:TextBox ID="txtOwner" runat="server" />
                                <b>
                                    <asp:RequiredFieldValidator ID="vOwner" runat="server" ControlToValidate="txtOwner" ErrorMessage="请输入持卡人姓名" SetFocusOnError="True" ValidationGroup="Insert"></asp:RequiredFieldValidator>
                                </b>
                            </td>
                        </tr>
                        <tr align="left">
                            <td align="right">持卡人变动情况</td>
                            <td>
                                <asp:TextBox ID="txtOwnerDetail" runat="server" TextMode="MultiLine" Rows="8" /></td>
                        </tr>
                        <tr align="left">
                            <td align="right">余额<font color="red">*</font></td>
                            <td>
                                <asp:TextBox ID="txtBalance" runat="server" Text="0" Style="ime-mode: disabled" onkeypress="if((event.keyCode<48 ||event.keyCode>57) &&event.keyCode!=46) {event.returnValue=false;} else {event.returnValue=true;}" />
                                <b>
                                    <asp:RequiredFieldValidator ID="vBalance" runat="server" ControlToValidate="txtBalance" ErrorMessage="请输入卡内余额" Display="Dynamic" SetFocusOnError="True" ValidationGroup="Insert"></asp:RequiredFieldValidator>
                                    <asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server" ControlToValidate="txtBalance" Display="Dynamic" ErrorMessage="余额必须大于等于0" SetFocusOnError="True" ValidationExpression="\d+(.\d+)?" ValidationGroup="Insert"></asp:RegularExpressionValidator>
                                </b></td>
                        </tr>
                        <tr align="left">
                            <td align="right">主页面显示<font color="red">*</font></td>
                            <td>
                                <asp:CheckBox ID="cbShow" runat="server" Checked="true" Text="" /></td>
                        </tr>
                        <tr align="left">
                            <td align="right">启用<font color="red">*</font></td>
                            <td>
                                <asp:CheckBox ID="cbEnabled" runat="server" Checked="true" Text="" /></td>
                        </tr>
                        <tr align="left">
                            <td align="right">排序<font color="red">*</font></td>
                            <td>
                                <asp:TextBox ID="txtOrder" runat="server" Text="0" Style="ime-mode: disabled" onkeypress="if((event.keyCode<48 ||event.keyCode>57) &&event.keyCode!=46) {event.returnValue=false;} else {event.returnValue=true;}" />
                                <b>
                                    <asp:RequiredFieldValidator ID="vOrder" runat="server" ControlToValidate="txtOrder" ErrorMessage="请输入排序号" SetFocusOnError="True" Display="Dynamic" ValidationGroup="Insert"></asp:RequiredFieldValidator>
                                    <asp:RegularExpressionValidator ID="RegularExpressionValidator2" runat="server" ControlToValidate="txtOrder" Display="Dynamic" ErrorMessage="余额必须大于等于0" SetFocusOnError="True" ValidationExpression="\d+(.\d+)?" ValidationGroup="Insert"></asp:RegularExpressionValidator>
                                </b>
                            </td>
                        </tr>
                    </tbody>
                </table>

                <span class="style8">
                    <br />
                </span>
                <br />
                <span class="style6">
                    <asp:Button ID="Button1" runat="server" CssClass="style1"
                        OnClick="Button1_Click" Text="添加" ValidationGroup="Insert" />&nbsp;&nbsp;<asp:Button ID="Button3" runat="server" PostBackUrl="~/index.aspx" Text="返回主页面" />
                    <br />
                </span>
            </b>
            <span class="style21">&nbsp;
        &nbsp; </span>
            <span class="style21">&nbsp;&nbsp;</span><br class="style1" />
            <span class="style21">添加人：</span><asp:Label ID="Label1" runat="server"
                CssClass="style21" Text="Label"></asp:Label>
            <span class="style21">&nbsp; </span>
            <asp:Label ID="Label2" runat="server" CssClass="style21" Text="Label"></asp:Label>
            <span class="style21">&nbsp; </span>
            <asp:Label ID="Label3" runat="server" CssClass="style21" Text="Label"></asp:Label>
        </div>
    </form>
    <p class="style21" style="text-align: center">
        &nbsp;<br />
        &nbsp;安康供电段信息中心制作 2015
    </p>
</body>
</html>
